import { NetService } from '@core/http'
import { Injectable } from '@angular/core'
import { of } from 'rxjs'

import { productController } from '../config/service/product.controller'
import productList from '../../assets/json/product-list.json'
// import comboList from '../../assets/json/combo-list.json'
import customerTagList from '../../assets/json/customer-tag.json'
import customerList from '../../assets/json/customer.json'
import customerGroupList from '../../assets/json/customer-group.json'
import {customerController} from "../../../../customer/src/app/config/service/customer.controller";

@Injectable()
export class ApiService {
  constructor(private net: NetService) {}
  //获取产品目录
  public getCatalogList(cursor?) {
    return this.net.send({
      service: productController.getProCatalogList,
      cursor
    })
  }
  //通过目录id查询产品列表
  public getProductList(cursor?) {
    return this.net.send({
      service: productController.getProductList,
      cursor
    })
  }
 //查询产品详情
  public getProduct(id) {
    // const product = productList.find(x => x.id === Number(id)) as any
    // const target = productList.find(item => item.id === product.parent)
    // product.productType = target.name
    // return of(product)
    return this.net.send({
      service: productController.getProductById,
      append:[id]
    })
  }
 //获取产品组合列表
  public getcomboList(cursor?) {
     return this.net.send({
      service: productController.getProductComboList,
       cursor
    })
  }
//获取产品组合详情
  public getcomboDetail(id) {
    return this.net.send({
      service: productController.getProductComboById,
      append:[id]
    })
  }
  //获取产品组合中的产品列表
  public getproductNum(cursor?) {
    return this.net.send({
      service: productController.getproductNum,
      cursor
    })
  }
  public getAttentionList(cursor?){
    return this.net.send({
      service: productController.getAttentionList,
      cursor
    })
  }

  public getCustomerTagList(type?, parent?) {
    return of(
      customerTagList
        .filter(x => type === undefined || x.type === type)
        .filter(x => parent === undefined || x.parent === parent)
    )
  }

  public getCustomerList() {
    return of(customerList)
  }

  public getCustomerGroupList() {
    return of(customerGroupList)
  }

  public delProduct(){
    return this.net.send({
      service: productController.delProduct,
    })
  }
  public focusProduct(data){
    console.log('eeeeeeeeeeeeee')
    return this.net.send({
      service: productController.focusproduct,
      params:data
    })
  }
  public creatproduct(){
    return this.net.send({
      service: productController.creatproduct
    })
  }

  public creatcombo(){
    return this.net.send({
      service: productController.creatcombo,
    })
  }
  public creatGroup(params){
    return this.net.send({
      service: productController.creatgroup,
      params:params
    })
  }
  public updateGroup(params,id){
    console.log("par: "+JSON.stringify(params));
    return this.net.send({
      service: productController.updategroup,
      append:[id],
      params:params
    })
  }
  public delGroupProduct(rowcode){
    return this.net.send({
      service: productController.delgroupProduct,
      append:[rowcode]
    })
  }
  public addGroupProduct(params,id){
    return this.net.send({
      service: productController.addGroupProduct,
      append:[id],
      params:params
    })
  }
  public delGroup(groupcode){
    return this.net.send({
      service: productController.delgroup,
      append:[groupcode]
    })
  }
  public delFocus(productcode){
    return this.net.send({
      service: productController.delFocus,
      append:[productcode]
    })
  }
}
